#include "lockwidget.h"
#include "ui_lockwidget.h"

LockWidget::LockWidget(QWidget *parent) :
    QWidget(parent, Qt::FramelessWindowHint | Qt::Window | Qt::WindowMinimizeButtonHint)
        , ui(new Ui::LockWidget)
{
    setWindowFlag(Qt::FramelessWindowHint, true);
    setWindowFlag(Qt::Window, true);
    setWindowFlag(Qt::WindowMinimizeButtonHint, true);
    setAttribute(Qt::WA_TranslucentBackground);

    ui->setupUi(this);
}

LockWidget::~LockWidget()
{
    delete ui;
}

void LockWidget::mousePressEvent(QMouseEvent*event)
{
    if(event->button()==Qt::LeftButton) //如果鼠标左键按下
    {
        isPressed=true;
        curPos = event->pos();    //记录当前的点击坐标
    }
}

void LockWidget::mouseMoveEvent(QMouseEvent*event)
{
    if(isPressed) //如果鼠标左键按下
    {
        this->move(event->pos()-curPos+this->pos());
        //窗口移动
    }
}

//鼠标释放
void LockWidget::mouseReleaseEvent(QMouseEvent*event)
{
    isPressed=false;
}

void LockWidget::paintEvent(QPaintEvent *event)
{
    No1 = {ui->btnMuDanGuangChang, ui->btnQiLiHe, ui->btnWangChengGongYuan, ui->btnJieFangLu,
                    ui->btnZhouWangChengGuangChang, ui->btnZhouWangChengGuangChang, ui->btnYingTianFu,
                   ui->btnMuDanQiao, ui->btnMuDanGuangChang
                  };
    No2 = {ui->btnErLiTun, ui->btnFengQingLu, ui->btnZhangJiaCun, ui->btnWangChengGongYuan,
                    ui->btnJieFangLu, ui->btnZhouWangChengGuangChang, ui->btnWenBoYuan,
                   ui->btnYingTianFu, ui->btnBoLanZhongXing, ui->btnYanYa, ui->btnHuangYa
                  };
    No3 = {ui->btnQingHuaFuZhong, ui->btnLiuCai, ui->btnShaMen, ui->btnJieFangLu,
                    ui->btnZhouWangChengGuangChang, ui->btnWenBoYuan, ui->btnYingTianFu,
                   ui->btnMuDanQiao, ui->btnDongDaJie, ui->btnFengZhuang, ui->btnNanSanHuan
                  };
    No4 = {ui->btnBeiSanHuan, ui->btnDongFengLu, ui->btnGuanHuTun, ui->btnZhouWangChengGuangChang,
                    ui->btnWenBoYuan, ui->btnYingTianFu, ui->btnMuDanQiao,
                   ui->btnMuDanGuangChang, ui->btnRenMingYiYuan, ui->btnJinDai, ui->btnYaoZhuang
                  };
    No5 = {ui->btnFengHuangTai, ui->btnMingHangLu, ui->btnErLiGang, ui->btnWenBoYuan,
                    ui->btnYingTianFu, ui->btnMuDanQiao, ui->btnMuDanGuangChang,
                   ui->btnQiLiHe, ui->btnHuangHeLu, ui->btnHaiTanSi, ui->btnXiYiHuan
                  };
    QStyleOption opt;
    opt.init(this);
    QPainter painter(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

    QPen pen; //画笔。绘制图形边线，由颜色、宽度、线风格等参数组成

    pen.setWidth(6);
    //可在QPaintDevice上绘制各种图形。QPaintDevice有之类QWidget、QImage、QOpenGLPaintDevice等

    //二号线

    pen.setColor(QColor(0, 170, 0));
    painter.setPen(pen);
    for(int i = 0; i < No2.count() - 1; i++){
        QPoint p1 = No2.at(i)->pos();
        QPoint p2 = No2.at(i+1)->pos();
        p1.setX(p1.x()+10);
        p1.setY(p1.y()+10);
        p2.setX(p2.x()+10);
        p2.setY(p2.y()+10);
        painter.drawLine(p1, p2);   //QPainter绘制直线
    }



    //三号线
    pen.setColor(QColor(255, 85, 0));
    painter.setPen(pen);
    for(int i = 0; i < No3.count() - 1; i++){
        QPoint p1 = No3.at(i)->pos();
        QPoint p2 = No3.at(i+1)->pos();
        p1.setX(p1.x()+10);
        p1.setY(p1.y()+10);
        p2.setX(p2.x()+10);
        p2.setY(p2.y()+10);
        painter.drawLine(p1, p2);   //QPainter绘制直线
    }



    //四号线

    pen.setColor(QColor(0, 170, 255));
    painter.setPen(pen);
    for(int i = 0; i < No4.count() - 1; i++){
        QPoint p1 = No4.at(i)->pos();
        QPoint p2 = No4.at(i+1)->pos();
        p1.setX(p1.x()+10);
        p1.setY(p1.y()+10);
        p2.setX(p2.x()+10);
        p2.setY(p2.y()+10);
        painter.drawLine(p1, p2);   //QPainter绘制直线
    }



    //五号线
    pen.setColor(QColor(85, 0, 255));
    painter.setPen(pen);
    for(int i = 0; i < No5.count() - 1; i++){
        QPoint p1 = No5.at(i)->pos();
        QPoint p2 = No5.at(i+1)->pos();
        p1.setX(p1.x()+10);
        p1.setY(p1.y()+10);
        p2.setX(p2.x()+10);
        p2.setY(p2.y()+10);
        painter.drawLine(p1, p2);   //QPainter绘制直线
    }


    pen.setColor(QColor(255, 167, 251));
    painter.setPen(pen);
    //一号线

    for(int i = 0; i < No1.count() - 1; i++){
        QPoint p1 = No1.at(i)->pos();
        QPoint p2 = No1.at(i+1)->pos();
        p1.setX(p1.x()+10);
        p1.setY(p1.y()+10);
        p2.setX(p2.x()+10);
        p2.setY(p2.y()+10);
        painter.drawLine(p1, p2);   //QPainter绘制直线
    }


}
